package com.zaofan.mobile.controller;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.zaofan.bean.Article;
import com.zaofan.service.ArticleService;

@WebServlet("/article")
public class ArticleController extends HttpServlet {
	private static final long serialVersionUID = -5377620282223515871L;
	private ArticleService articleService = new ArticleService();

	protected void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		detail(request, response);
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		doGet(request, response);
	}

	protected void detail(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		String temp = request.getParameter("id");
		try {
			Integer id = Integer.valueOf(temp);
			Article article = articleService.findById(id);
			request.setAttribute("article", article);
			request.getRequestDispatcher("/article.jsp").forward(request, response);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
